﻿using SuperX.Common.Log;
using SuperX.DataService;
using SuperX.DataService.Abstract;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Linq;

namespace SuperX.DeviceService
{
    public class DriverHelper
    {
        public static void GetDriverConfig(DriverConfig driver, string assembly, string className, string name)
        {
            try
            {
                string assemblyName = Path.Combine(Environment.CurrentDirectory, assembly);
                if (!File.Exists(assemblyName))
                    assemblyName = Path.Combine(Environment.CurrentDirectory, "Drivers", assembly);
                var ass = Assembly.LoadFrom(assemblyName);
                var dvType = ass.GetType(className);
                if (dvType != null)
                {
                    var method = dvType.GetMethod("GetDefaultConfig");
                    if (method != null && method.IsPublic)
                    {
                        method.Invoke(driver, new object[] { driver });
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Warn($"反射创建设备默认地址时异常：{ex.Message}");
            }
        }
    }
}